package com.epoint.mobileoa.tools;

import com.epoint.mobileoa.R;
import com.epoint.mobileoa.bizlogic.SuperView;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.text.Html;
import android.text.method.ScrollingMovementMethod;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;


/**
 * @author liyc
 * @time 2012-7-27 下午03:36:53
 * @annotation 自定义对话框
 */
public class EpointDialog {

	/**
	 * 显示一个自定义对话框
	 * showType 1--单纯提示，只有一个确定按钮，确定按钮无事件,点击后即关闭该对话框，确定事件传null值
	 * 			2--提示，两个按钮（确定，取消）,需传入确定按钮点击事件
	 */
	public static AlertDialog getDialog(Activity act,String msg,int showType,View.OnClickListener OKListener){  
		LayoutInflater factory = LayoutInflater.from(act);  

		View dlgEntryView = factory.inflate(R.layout.customdialoglayout, null);  
		Button btOk = (Button) dlgEntryView.findViewById(R.id.btn_dlg_ok);  
		Button btCancel = (Button) dlgEntryView.findViewById(R.id.btn_dlg_cancel);  
		TextView msgTxt = (TextView) dlgEntryView.findViewById(R.id.txt_dlg_msg);  
		TextView tvDlg_title = (TextView) dlgEntryView.findViewById(R.id.tvDlg_title);  
		tvDlg_title.setText(act.getString(R.string.prjname)+"                                     ");
		final AlertDialog dlg = new AlertDialog.Builder(act).create();  
		dlg.setView(dlgEntryView, 0, 0, 0, 0);  
		msgTxt.setText(msg);

		/*WindowManager m = act.getWindowManager();   

		Display d = m.getDefaultDisplay();  //为获取屏幕宽、高 
		LayoutParams p = dlg.getWindow().getAttributes();  //获取对话框当前的参数值   
		p.height = (int) (d.getHeight() * 0.6);   //高度设置为屏幕的0.6
		p.width = (int) (d.getWidth() * 0.95);    //宽度设置为屏幕的0.95   
		dlg.getWindow().setAttributes(p);  
		dlg.getWindow().setLayout(p.width,p.height);*/

		if(showType==1){
			btOk.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					dlg.dismiss();
				}
			});
			btCancel.setVisibility(View.GONE);
		}
		else if(showType==2){
			btOk.setOnClickListener(OKListener);
			btCancel.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					dlg.dismiss();
				}
			});
		}
		else if(showType==3){
			btOk.setOnClickListener(OKListener);
			btCancel.setVisibility(View.GONE);
		}
		msgTxt.setMovementMethod(ScrollingMovementMethod.getInstance());
		return dlg;
	}  

	public static void getDialog(Context con,String title,String msg){ 
		LayoutInflater factory = LayoutInflater.from(con);  

		View dlgEntryView = factory.inflate(R.layout.customdialoglayout, null);  
		Button btOk = (Button) dlgEntryView.findViewById(R.id.btn_dlg_ok);  
		Button btCancel = (Button) dlgEntryView.findViewById(R.id.btn_dlg_cancel);  
		TextView msgTxt = (TextView) dlgEntryView.findViewById(R.id.txt_dlg_msg);  
		TextView tvDlg_title = (TextView) dlgEntryView.findViewById(R.id.tvDlg_title); 
		title = title==null?"":title;
		if(title.equals("")){
			title = con.getString(R.string.prjname)+"                                     ";
		}
		tvDlg_title.setText(title);
		final AlertDialog dlg = new AlertDialog.Builder(con).create();  
		dlg.setView(dlgEntryView, 0, 0, 0, 0);  
		msgTxt.setText(Html.fromHtml(msg));
		btOk.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				dlg.dismiss();
			}
		});
		btCancel.setVisibility(View.GONE);

		msgTxt.setMovementMethod(ScrollingMovementMethod.getInstance());
		dlg.show();
	}
}
